package com.eos.orm.c3p0.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.eos.orm.c3p0.dao.AbstractC3p0Dao;
import com.eos.orm.c3p0.dao.DBConnectionManager;
import com.eos.orm.mybatis.model.DeliverList;

public class DeliverListDaoImpl extends AbstractC3p0Dao<DeliverList> {

	public boolean save(List<DeliverList> deliverList){
		Connection connection = DBConnectionManager.getConnection();
		String sql = "insert into `deliver_list` (`customer_id`, `activty_id`, `activty_son_id`, `product_id`, `brand_id`, `model_id`, `colour_id`, `case_number`, `bar_code`, `product_count`, `deliver_time`, `insert_user_id`, `insert_time`, `deliver_desc`, `status`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		boolean flag = false;
		PreparedStatement pstm = null;
		try {
			pstm = connection.prepareStatement(sql);
			for(DeliverList dl : deliverList){
				pstm.setInt(1, dl.getCustomerId());
				pstm.setInt(2, dl.getActivtyId());
				pstm.setInt(3, dl.getActivtySonId());
				pstm.setInt(4, dl.getProductId());
				pstm.setInt(5, dl.getBrandId());
				pstm.setInt(6, dl.getModelId());
				pstm.setInt(7, dl.getColourId());
				pstm.setString(8, dl.getCaseNumber());
				pstm.setString(9, dl.getBarCode());
				pstm.setInt(10, dl.getProductCount());
				pstm.setString(11, dl.getDeliverTime());
				pstm.setString(12, dl.getInsertUserId());
				pstm.setString(13, dl.getInsertTime());
				pstm.setString(14, dl.getDeliverDesc());
				pstm.setString(15, dl.getStatus());
				pstm.addBatch();
			}
			int[] rlts = pstm.executeBatch();
			if(null != rlts && rlts.length > 0){
				flag = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			flag = false;
		}finally {
			freeResource(connection, pstm, null);
		}
		return flag;
	}
}
